/**
 * @author	Don Koenig, Brett, Natalie
 * Company:  1186 Entertainment
 * Date Modified:  3/13/07
 * Filename:  ClientThread.java
 */

import java.awt.*;
import java.applet.*;
import java.net.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Date;
import java.lang.Object;
import java.util.*;
import java.lang.Thread.*;
import java.io.*;
import java.net.*;
import java.text.*;

public class GameSelect extends JPanel implements ActionListener
{
	public static String DELIM = "&";
	JPanel textPane, buttonPane;

	JButton playReversiButton, logoutButton;
	ClientApplet ca;

	public GameSelect(ClientApplet client_applet)
	{
		ca = client_applet;

		Font f = new Font("Dialog" , Font.BOLD , 14);
		Color c=new Color(10,102,255);

		playReversiButton = new JButton("Play Reversi");
		playReversiButton.addActionListener(this);
		logoutButton = new JButton("Logout");
		logoutButton.addActionListener(this);

		//top panel
		JPanel topPanel = new JPanel();
		JLabel lblSelect = new JLabel("Select a game to play or ");
		lblSelect.setFont(f);
		lblSelect.setForeground(c);
		topPanel.add(lblSelect);
		topPanel.add(logoutButton);

		//reversi panel
		JPanel revPanel = new JPanel(new BorderLayout());
		//set picture
		ImageIcon iconRev = new ImageIcon(ca.getImage(ca.getDocumentBase(), "files/reversi.jpg"));
		//ImageIcon iconRev = new ImageIcon("files/reversi.jpg");
		JLabel picRev = new JLabel();
		picRev.setIcon(iconRev);
		//add
		revPanel.add(picRev, BorderLayout.NORTH);
		revPanel.add(playReversiButton);

		String[] comSoon = {"files/hangman.jpg", "files/tictac.jpg"};
		int i = 0;

		JPanel[] gamPanel = new JPanel[comSoon.length];
		ImageIcon[] iconGam = new ImageIcon[comSoon.length];
		JLabel[] picGam = new JLabel[comSoon.length];
		JLabel[] lblGam = new JLabel[comSoon.length];

		for(i=0; i<comSoon.length; i++)
		{
			//game panel
			gamPanel[i] = new JPanel(new BorderLayout());
			//set picture
			iconGam[i] = new ImageIcon(ca.getImage(ca.getDocumentBase(),comSoon[i]));
			picGam[i] = new JLabel();
			picGam[i].setIcon(iconGam[i]);
			//add
			gamPanel[i].add(picGam[i], BorderLayout.NORTH);
			lblGam[i] = new JLabel("Coming soon!");
			gamPanel[i].setBackground(Color.WHITE);
			gamPanel[i].add(lblGam[i]);
		}

		JPanel midPanel = new JPanel();
		//top, left, bottom, right
		midPanel.setBorder(BorderFactory.createEmptyBorder(0,10,0,10));
		midPanel.add(revPanel);

		for(i=0; i<comSoon.length; i++)
		{
			midPanel.add(gamPanel[i]);
		}

		//add to this panel
		this.setLayout(new BorderLayout());
		this.add(topPanel, BorderLayout.NORTH);
		this.add(midPanel, BorderLayout.SOUTH);

		//set background to white
		this.setBackground(Color.WHITE);
		topPanel.setBackground(Color.WHITE);
		revPanel.setBackground(Color.WHITE);
		midPanel.setBackground(Color.WHITE);

		playReversiButton.transferFocus();
		setSize(800, 600);
		setVisible(true);
	}

	public void actionPerformed(ActionEvent ae)
	{
		String msg;
		JButton button=(JButton)ae.getSource(); //get the source of the event
		if(button.equals(playReversiButton))
		{
			ca.send("4" + DELIM + "0");
			//ca.loadPanel(new GameLobby());
		}
		else if(button.equals(logoutButton))
		{
			//msg = "8";
			//ca.send(msg);

			//go back to login screen
			System.out.println("Logout Pressed. Switching to Login Screen.");
			//ca.loadPanel(new Login(ca));
			ca.logout();
		}
	}
}
